package com.ymatou.iapi.csim.testcase;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetHistorySessionListResp;
import com.ymatou.iapi.csim.parameter.GetHistorySessionsBySessionNumberBean;
import com.ymatou.iapi.csim.parameter.SendMessageCSBean;
import com.ymatou.iapi.csim.parameter.GetHistorySessionListResp.cssession;
import com.ymatou.iapi.csim.service.GetHistorySessionsBySessionNumberCall;
import com.ymatou.iapi.csim.service.SendMessageCSCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
/**
*根据多个会话编号获取会话列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetHistorySessionsBySessionNumber{
	private static GetHistorySessionsBySessionNumberBean bean;
	private static GetHistorySessionsBySessionNumberCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private Integer csId_seller=Integer.parseInt(EnvSetup.getData("csId_seller").toString());
	private static Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private Integer sellerId=Integer.parseInt(EnvSetup.getData("autotest_seller1").toString());
	private static ymt_cssessionWapper csSessionWapper=new ymt_cssessionWapper();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据多个会话编号获取会话列表");
	}

	@Before
	public void caseUp() {
		bean=new GetHistorySessionsBySessionNumberBean();
		call=new GetHistorySessionsBySessionNumberCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetHistorySessionsBySessionNumber_001() {
		Logger.start(true,"根据多个会话编号获取会话列表-查询一条会话");
		try {
			//客服上线
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			SendMessageCSCall sendMessageCSCall=service.setSendMessageCSCall(sendMessageCSBean);
			List<String> list=new ArrayList();
			list.add(cssession.getSessionNumber());
			bean.setSessionNumbers(list);
			call.setData(bean);
			call.callService();			
			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetHistorySessionsBySessionNumber_002() {
		Logger.start(true,"根据多个会话编号获取会话列表-查询多条会话");
		try {
			//客服上线
			service.getOnlineCS(csId);
			service.getOnlineCS_Seller(csId_seller);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//打开会话
			ymt_cssession cssession2=service.getOpenSession(csId_seller,sellerId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			SendMessageCSCall sendMessageCSCall=service.setSendMessageCSCall(sendMessageCSBean);
			
			SendMessageCSBean sendMessageCSBean2=service.setSendMessageCSBean();
			sendMessageCSBean2.setSessionId(cssession2.getId());
			sendMessageCSBean2.setCsId(csId_seller);
			sendMessageCSBean2.setUserId(sellerId);
			SendMessageCSCall sendMessageCSCall2=service.setSendMessageCSCall(sendMessageCSBean2);
			
			List<String> list=new ArrayList();
			list.add(cssession.getSessionNumber());
			list.add(cssession2.getSessionNumber());
			
			bean.setSessionNumbers(list);
			call.setData(bean);
			call.callService();			
			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	private void verifyReturn()
	{
      List<ymt_cssession>  cssessionList=csSessionWapper.selectBysessionNumber(bean.getSessionNumbers());
      GetHistorySessionListResp resp=call.GetHistorySessionList();
      
      Logger.verifyEquals(0, resp.getErrorCode(), "验证返回的ErrorCode");
      for(int i=0;i<call.GetHistorySessionList().getResult().size();i++)
      {
    	  cssession csReturn=call.GetHistorySessionList().getResult().get(i);
    	  ymt_cssession cs=cssessionList.get(i);
    	  Logger.verifyEquals(cs.getId(), csReturn.getSessionId(), "验证返回的sessionId");
    	  Logger.verifyEquals(cs.getSessionNumber(), csReturn.getSessionNumber(), "验证返回的SessionNumber");
    	  Logger.verifyEquals(cs.getCSId(), csReturn.getCSId(), "验证返回的CSId");
    	  Logger.verifyEquals(cs.getUserId(), csReturn.getUserId(), "验证返回的UserId");
    	  Logger.verifyEquals(cs.getUserType(), csReturn.getUserType(), "验证返回的UserType");
    	  Logger.verifyEquals(dateFormat.format(cs.getLaunchTime()), csReturn.getLaunchTime(), "验证返回的LaunchTime");
    	  
    	  Logger.verifyEquals(dateFormat.format(cs.getBeginTime()), csReturn.getBeginTime(), "验证返回的BeginTime");
    	  Logger.verifyEquals(cs.getEndTime()==null?null:dateFormat.format(cs.getEndTime()), csReturn.getEndTime(), "验证返回的EndTime");
    	  Logger.verifyEquals(cs.getStatus(), csReturn.getStatus(), "验证返回的Status");
    	  Logger.verifyEquals(cs.getOpenType(), csReturn.getOpenType(), "验证返回的OpenType");
    	  Logger.verifyEquals(cs.getCloseType()==null?0:cs.getCloseType(), csReturn.getCloseType(), "验证返回的CloseType");
    	  Logger.verifyEquals(cs.getFromPlatform(), csReturn.getFromPlatform(), "验证返回的FromPlatform");
    	  Logger.verifyEquals(cs.getIsSendScore(), csReturn.getIsSendScore(), "验证返回的IsSendScore");
    	  Logger.verifyEquals(cs.getScore()==null?0:cs.getScore(), cs.getScore()==null?0:csReturn.getScore(), "验证返回的Score");
    	  Logger.verifyEquals(cs.getMark()==null?0:cs.getMark(), cs.getMark()==null?0:csReturn.getMark(), "验证返回的Mark");
    	  Logger.verifyEquals(cs.getFromCSId(), csReturn.getFromCSId(), "验证返回的FromCSId");
    	  Logger.verifyEquals(cs.getMessageSource(), csReturn.getMessageSource(), "验证返回的MessageSource");
    	  Logger.verifyEquals(cs.getSourceParams(), csReturn.getSourceParams(), "验证返回的SourceParams");
    	  Logger.verifyEquals(cs.getQuestionGuideId(), csReturn.getQuestionGuideId(), "验证返回的QuestionGuideId");
      }
	}
}


